<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/5/27
 * Time: 15:49
 */

namespace app\admin\controller;

use think\Controller;
use think\Validate;
use app\admin\Model\Admin;


class Login extends Base
{


    public function index(){

        if(!empty($this->AdminInfo)){
            $this->redirect($this->goto);
            exit;
        }
        return view('login',['message'=>'']);

    }

    public function checkout(){
        $list['name']=htmlspecialchars($this->request->post('name'));
        $list['password']=htmlspecialchars($this->request->post('password'));
        $rules=[
            'name'=>'require|max:20|min:3',
            'password'=>'require',
        ];
        $field =[
            'name'=>'用户名',
            'password'=>'密码',
        ];
        $validate = new Validate($rules,[],$field);
        if(!$validate->check($list)){
            return view('login',['message'=>$validate->getError()]);
        }else{
            $res= Admin::login($list);
            if($res){
                if($res.status!==10){
                    return view('login',['message'=>'该用户被限制']);
                    exit;
                }
                //session($data);
                return view('login',['message'=>'登录成功']);
            }else{
                return view('login',['message'=>'登录成功']);
                //return view('login',['message'=>'用户名或密码错误']);
            }
        }
    }




}